home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / util / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  3.0 KB  |  150 lines

  1. package java.util;
  2.  
  3. public class Timer {
  4.    private TaskQueue queue;
  5.    private TimerThread thread;
  6.    private Object threadReaper;
  7.    private static int nextSerialNumber = 0;
  8.  
  9.    private static synchronized int serialNumber() {
  10.       return nextSerialNumber++;
  11.    }
  12.  
  13.    public Timer() {
  14.       this("Timer-" + serialNumber());
  15.    }
  16.  
  17.    public Timer(boolean var1) {
  18.       this("Timer-" + serialNumber(), var1);
  19.    }
  20.  
  21.    public Timer(String var1) {
  22.       this.queue = new TaskQueue();
  23.       this.thread = new TimerThread(this.queue);
  24.       this.threadReaper = new 1(this);
  25.       this.thread.setName(var1);
  26.       this.thread.start();
  27.    }
  28.  
  29.    public Timer(String var1, boolean var2) {
  30.       this.queue = new TaskQueue();
  31.       this.thread = new TimerThread(this.queue);
  32.       this.threadReaper = new 1(this);
  33.       this.thread.setName(var1);
  34.       this.thread.setDaemon(var2);
  35.       this.thread.start();
  36.    }
  37.  
  38.    public void schedule(TimerTask var1, long var2) {
  39.       if (var2 < 0L) {
  40.          throw new IllegalArgumentException("Negative delay.");
  41.       } else {
  42.          this.sched(var1, System.currentTimeMillis() + var2, 0L);
  43.       }
  44.    }
  45.  
  46.    public void schedule(TimerTask var1, Date var2) {
  47.       this.sched(var1, var2.getTime(), 0L);
  48.    }
  49.  
  50.    public void schedule(TimerTask var1, long var2, long var4) {
  51.       if (var2 < 0L) {
  52.          throw new IllegalArgumentException("Negative delay.");
  53.       } else if (var4 <= 0L) {
  54.          throw new IllegalArgumentException("Non-positive period.");
  55.       } else {
  56.          this.sched(var1, System.currentTimeMillis() + var2, -var4);
  57.       }
  58.    }
  59.  
  60.    public void schedule(TimerTask var1, Date var2, long var3) {
  61.       if (var3 <= 0L) {
  62.          throw new IllegalArgumentException("Non-positive period.");
  63.       } else {
  64.          this.sched(var1, var2.getTime(), -var3);
  65.       }
  66.    }
  67.  
  68.    public void scheduleAtFixedRate(TimerTask var1, long var2, long var4) {
  69.       if (var2 < 0L) {
  70.          throw new IllegalArgumentException("Negative delay.");
  71.       } else if (var4 <= 0L) {
  72.          throw new IllegalArgumentException("Non-positive period.");
  73.       } else {
  74.          this.sched(var1, System.currentTimeMillis() + var2, var4);
  75.       }
  76.    }
  77.  
  78.    public void scheduleAtFixedRate(TimerTask var1, Date var2, long var3) {
  79.       if (var3 <= 0L) {
  80.          throw new IllegalArgumentException("Non-positive period.");
  81.       } else {
  82.          this.sched(var1, var2.getTime(), var3);
  83.       }
  84.    }
  85.  
  86.    private void sched(TimerTask var1, long var2, long var4) {
  87.       if (var2 < 0L) {
  88.          throw new IllegalArgumentException("Illegal execution time.");
  89.       } else {
  90.          synchronized(this.queue) {
  91.             if (!this.thread.newTasksMayBeScheduled) {
  92.                throw new IllegalStateException("Timer already cancelled.");
  93.             } else {
  94.                synchronized(var1.lock) {
  95.                   if (var1.state != 0) {
  96.                      throw new IllegalStateException("Task already scheduled or cancelled");
  97.                   }
  98.  
  99.                   var1.nextExecutionTime = var2;
  100.                   var1.period = var4;
  101.                   var1.state = 1;
  102.                }
  103.  
  104.                this.queue.add(var1);
  105.                if (this.queue.getMin() == var1) {
  106.                   this.queue.notify();
  107.                }
  108.  
  109.             }
  110.          }
  111.       }
  112.    }
  113.  
  114.    public void cancel() {
  115.       synchronized(this.queue) {
  116.          this.thread.newTasksMayBeScheduled = false;
  117.          this.queue.clear();
  118.          this.queue.notify();
  119.       }
  120.    }
  121.  
  122.    public int purge() {
  123.       int var1 = 0;
  124.       synchronized(this.queue) {
  125.          for(int var3 = this.queue.size(); var3 > 0; --var3) {
  126.             if (this.queue.get(var3).state == 3) {
  127.                this.queue.quickRemove(var3);
  128.                ++var1;
  129.             }
  130.          }
  131.  
  132.          if (var1 != 0) {
  133.             this.queue.heapify();
  134.          }
  135.  
  136.          return var1;
  137.       }
  138.    }
  139.  
  140.    // $FF: synthetic method
  141.    static TaskQueue access$000(Timer var0) {
  142.       return var0.queue;
  143.    }
  144.  
  145.    // $FF: synthetic method
  146.    static TimerThread access$100(Timer var0) {
  147.       return var0.thread;
  148.    }
  149. }
  150.